define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user_table/index' + location.search,
                    add_url: 'user_table/add',
                    edit_url: 'user_table/edit',
                    del_url: 'user_table/del',
                    multi_url: 'user_table/multi',
                    import_url: 'user_table/import',
                    table: 'user_table',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'pid', title: __('Pid')},
                        {field: 'real_name', title: __('Real_name'), operate: 'LIKE'},
                        {field: 'username', title: __('Username'), operate: 'LIKE'},
                        {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
                        {field: 'password', title: __('Password'), operate: 'LIKE'},
                        {field: 'salt', title: __('Salt'), operate: 'LIKE'},
                        {field: 'pay_password', title: __('Pay_password'), operate: 'LIKE'},
                        {field: 'pay_salt', title: __('Pay_salt'), operate: 'LIKE'},
                        {field: 'idcard', title: __('Idcard'), operate: 'LIKE'},
                        {field: 'email', title: __('Email'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'avatar', title: __('Avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'level_id', title: __('Level_id')},
                        {field: 'gender', title: __('Gender'), searchList: {"0":__('Gender 0'),"1":__('Gender 1'),"2":__('Gender 2')}, formatter: Table.api.formatter.normal},
                        {field: 'birthday', title: __('Birthday'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'bio', title: __('Bio'), operate: 'LIKE'},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'score', title: __('Score'), operate:'BETWEEN'},
                        {field: 'ten_prize_money', title: __('Ten_prize_money'), operate:'BETWEEN'},
                        {field: 'invite_code', title: __('Invite_code'), operate: 'LIKE'},
                        {field: 'invitation_num', title: __('Invitation_num')},
                        {field: 'today_active', title: __('Today_active'), operate:'BETWEEN'},
                        {field: 'last_active', title: __('Last_active'), operate:'BETWEEN'},
                        {field: 'is_nine', title: __('Is_nine'), searchList: {"1":__('Is_nine 1'),"-1":__('Is_nine -1')}, formatter: Table.api.formatter.normal},
                        {field: 'is_ten', title: __('Is_ten'), searchList: {"1":__('Is_ten 1'),"-1":__('Is_ten -1')}, formatter: Table.api.formatter.normal},
                        {field: 'is_effect', title: __('Is_effect')},
                        {field: 'effect_user', title: __('Effect_user')},
                        {field: 'prize_total', title: __('Prize_total')},
                        {field: 'alerday_pin_total', title: __('Alerday_pin_total')},
                        {field: 'group_num', title: __('Group_num')},
                        {field: 'group_num_all', title: __('Group_num_all')},
                        {field: 'today_prize', title: __('Today_prize'), operate:'BETWEEN'},
                        {field: 'all_prize', title: __('All_prize'), operate:'BETWEEN'},
                        {field: 'successions', title: __('Successions')},
                        {field: 'maxsuccessions', title: __('Maxsuccessions')},
                        {field: 'openid', title: __('Openid'), operate: 'LIKE'},
                        {field: 'prevtime', title: __('Prevtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'logintime', title: __('Logintime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'loginip', title: __('Loginip'), operate: 'LIKE'},
                        {field: 'loginfailure', title: __('Loginfailure')},
                        {field: 'joinip', title: __('Joinip'), operate: 'LIKE'},
                        {field: 'jointime', title: __('Jointime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'token', title: __('Token'), operate: 'LIKE'},
                        {field: 'status_switch', title: __('Status_switch'), searchList: {"1":__('Status_switch 1'),"0":__('Status_switch 0')}, table: table, formatter: Table.api.formatter.toggle},
                        {field: 'verification', title: __('Verification'), operate: 'LIKE'},
                        {field: 'state', title: __('State'), searchList: {"1":__('State 1'),"2":__('State 2')}, formatter: Table.api.formatter.normal},
                        {field: 'level.title', title: __('Level.title'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});